import { Directive,Input,ViewContainerRef,TemplateRef } from '@angular/core';

@Directive({
  selector: '[range]'
})
export class RangeDirDirective {
    _range:number[]=[]
    constructor(private tlf:TemplateRef<any>,private vcf:ViewContainerRef) { }
    @Input()
    set range(value:number[]){
        this.vcf.clear();
        this._range=this.generateRange(value[0],value[1]);
        this._range.forEach(num=>{
            this.vcf.createEmbeddedView(this.tlf,{$implicit:num*num})
        })
    }



    generateRange(start:number,end:number):number[]{
        var number:number[]=[];
        for(let i=start;i<=end;i++){
            number.push(i)
        }
        return number;
    }
} 
